#if 0

#include <iostream>
#include <cassert>

using namespace std;

class CUnionFindSet {
private:
	int m_nN;
	int *m_pParent;
public:
	CUnionFindSet(int i);
	~CUnionFindSet();
	int Find(int i);
	void Union(int i, int j);
};

CUnionFindSet::CUnionFindSet(int i) {
	m_nN = i;
	if (i < 0 || i > 1000)
		assert(0 && "not a legal number");
	m_pParent = new int[m_nN];
	for (int i = 0; i < m_nN; ++i) {
		m_pParent[i] = i;
	}
}

CUnionFindSet::~CUnionFindSet() {
	if (m_pParent != NULL) {
		delete[] m_pParent;
		m_pParent = NULL;
	}
}

int CUnionFindSet::Find(int i) {
	if (i<0 || i >= m_nN) {
		return -1;
	}

	int root = i;
	while (root != m_pParent[root]) {
		root = m_pParent[root];
	}
	int t = i;
	int p;
	while (t != root) {
		p = m_pParent[t];
		m_pParent[t] = root;
		t = p;
	}

	return root;
}

void CUnionFindSet::Union(int i, int j) {
	if (i<0 ||i>= m_nN || j < 0 || j >= m_nN) {
		return;
	}

	int ri = Find(i);
	int rj = Find(j);
	if (ri != rj) {
		m_pParent[ri] = rj;
	}
}


int CalcComponent() {
	const int N = 10;
	CUnionFindSet ufs(N);
	ufs.Union(2, 6);
	ufs.Union(5, 6);
	ufs.Union(1, 8);
	ufs.Union(2, 9);
	ufs.Union(5, 3);
	ufs.Union(4, 8);
	ufs.Union(4, 0);

	int* component = new int[N];
	memset(component, 0, N*sizeof(component[0]));
	for (int i = 0; i < N; ++i) {
		component[ufs.Find(i)]++;
	}

	int nComponent = 0;
	for (int i = 0; i < N; ++i) {
		if (component[i] != 0) {
			nComponent++;
		}
	}
	delete[] component;
	return nComponent;
}

int main() {
	int num = CalcComponent();
	cout << "num is:" << num << endl;
	system("pause");
	return 0;
}


#endif